<?php


namespace app\crontab\controller\once;


use custom\Mongo;
use think\console\Command;
use think\console\Input;
use think\console\Output;

/**
 * 学段统计
 * Class SchoolStage
 * @package app\crontab\controller
 */
class SchoolStage extends Command {

    //wx_xqf_cz_details_data
    //wx_xqf_xx_details_data
    public static $setName = 'wx_xqf_cz_details_data';
    public static $type = 2;

    protected function configure() {
        $this->setName('SchoolStage');
    }

    protected function execute(Input $input, Output $output) {
        echo "start\n";
        $mongo = Mongo::getInstance();
        $options = [
            'projection' => ['_id' => 1, 'school_stage' => 1],
            'sort'       => ['id' => 1],
        ];
        $cursor = $mongo->select(self::$setName, [], $options);
        foreach ($cursor as $v1) {
            $v1 = (array)$v1;
            if ($v1['school_stage'] && empty(db("school_stage")->where('school_type', self::$type)->where('name', $v1['school_stage'])->select())) {
                db("school_stage")->insert([
                    'school_type' => self::$type,
                    'name'        => $v1['school_stage'],
                    'itime'       => time(),
                ]);
            }
        }
        echo "end\n";
    }

}